package com.ssm.pre.util;

import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.net.URL;
import java.net.URLConnection;
import java.security.MessageDigest;
import java.text.DateFormat;
import java.text.DecimalFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import javax.servlet.http.HttpServletResponse;

import com.ssm.util.Constants;
import com.ssm.util.object.InputObject;
import com.ssm.util.object.ObjectConstant;
import com.ssm.util.object.OutputObject;

import net.sf.json.JSON;
import net.sf.json.JSONSerializer;


public class ToolUtil {
	
	
	public static void main(String[] margs){
		//获取UUID字符串，替换request请求路径
		System.out.println(getSurFaceId().toString());
	}
	
	public static String getSurFaceId() {
		UUID uuid = java.util.UUID.randomUUID();
		return "" + uuid.toString().replaceAll("-", "");
	}
	
	/**
	 * 比较
	 * @param array
	 * @param v
	 * @return
	 */
	public static <T> int contains( T[] array, T v ) {
		int k = -1;
	    for ( T e : array ){
	    	k++;
	        if ( e == v || v != null && v.equals( e ) )
	            return k;
	    }
	    return k;
	}
	
	public static boolean contains(Map<String,Object> map, String[] key, String[] returnMessage, InputObject inputObject, OutputObject outputObject) {
		for(int i = 0;i<key.length;i++){
			if(map.containsKey(key[i].toString())){
				if(JudgeUtil.isNull(map.get(key[i].toString()).toString())){
					outputObject.setreturnMessage(returnMessage[i]);
					return false;
				}
			}else{
				outputObject.setreturnMessage(key[i]+"键不存在");
				return false;
			}
		}
	    return true;
	}
	
	public static <T> boolean containsBoolean( T[] array, T v ) {
	    for ( T e : array )
	        if ( e == v || v != null && v.equals( e ) )
	            return true;
	    return false;
	}
	
	public static String containsBoolean1(String [] ref,String str){
		for(String s : ref){
			switch (s.toLowerCase()) {
			case ObjectConstant.REQUIRED://不为空
				if(ToolUtil.isNull(str))
					return "不能为空";
				break;
			case ObjectConstant.NUM://数字类型不正确
				if(!ToolUtil.isNumeric(str))
					return "数字类型不正确";
				break;
			case ObjectConstant.DATE://时间类型不正确
				if(!ToolUtil.isDate(str))
					return "时间类型不正确";
				break;
			case ObjectConstant.EMAIL://邮箱类型不正确
				if(!ToolUtil.isEmail(str))
					return "邮箱类型不正确";
				break;
			case ObjectConstant.IDCARD://证件号类型不正确
				if(!ToolUtil.IsIDcard(str))
					return "证件号类型不正确";
				break;
			case ObjectConstant.PHONE://手机号类型不正确
				if(!ToolUtil.isPhoneNO(str))
					return "手机号类型不正确";
				break;
			case ObjectConstant.URL://请求链接类型不正确
				if(!ToolUtil.IsUrl(str))
					return "请求链接类型不正确";
				break;
			case ObjectConstant.IP://请求IP类型不正确
				if(!ToolUtil.isIP(str))
					return "请求IP类型不正确";
				break;
			case ObjectConstant.POSTCODE://国内邮编类型不正确
				if(!ToolUtil.IsPostalcode(str))
					return "国内邮编类型不正确";
				break;
			default:
				break;
			}
		}
		return null;
	}
	
	/**
	 * 将map集合转成json输出到前台
	 * 
	 * @param response
	 * @param pramers
	 */
	public static void ToJson(HttpServletResponse response, Map<String, Object> pramers) throws Exception {
		JSON context = JSONSerializer.toJSON(pramers);
		PrintWriter out = null;
		// 指定返回值的编码方式，必须放在out声明之前
		response.setCharacterEncoding("UTF-8");
		response.setContentType("text/html;charset=UTF-8");
		out = response.getWriter();// 获取输入流
		out.print(context);// 将信息发送到前台
		out.flush();// 刷新
		out.close();// 关闭输入流
	}
	
	/**
	 * 将list集合转成json
	 * 
	 * @param response
	 * @param pramers
	 */
	public static String getJsonStrFromList(List<?> pramers) throws Exception {
		JSON context = JSONSerializer.toJSON(pramers);
		return context.toString();
	}

	/**
	 * MD5加密技术
	 * 
	 * @param str
	 * @return
	 */
	public static String MD5(String str) throws Exception {
		byte[] bt = str.getBytes();
		StringBuffer sbf = null;
		MessageDigest md = null;
		md = MessageDigest.getInstance("MD5");
		byte[] bt1 = md.digest(bt);
		sbf = new StringBuffer();
		for (int i = 0; i < bt1.length; i++) {
			int val = ((int) bt1[i]) & 0xff;
			if (val < 16)
				sbf.append("0");
			sbf.append(Integer.toHexString(val));
		}
		return sbf.toString();
	}

	/**
	 * 对先有日期进行调整 日期迁移后退
	 * 
	 * @param nowDay
	 *            设定现在的日期
	 * @param field
	 *            取1加1年,取2加半年,取3加一季度,取4加一周,取5加一天
	 * @param amount
	 *            增加量 正数日期将后加，负数日期将前推
	 * @return
	 */
	public static String changeDay(String nowDay, int field, int amount) throws Exception {
		SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
		GregorianCalendar gc = new GregorianCalendar();
		Date date = format.parse(nowDay);
		gc.setTime(date);
		gc.add(field, amount);
		return format.format(gc.getTime());
	}

	/**
	 * 比较两个日期之间相差的天数daysBetween("2016-12-17","2016-12-29")
	 * 
	 * @param stareTime
	 *            开始日期 较小的日期
	 * @param endTime
	 *            结束日期，比较大的日期
	 * @return
	 * @throws Exception
	 */
	public static int daysBetween(String stareTime, String endTime) throws Exception {
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
		Calendar cal = Calendar.getInstance();
		cal.setTime(sdf.parse(stareTime));
		long time1 = cal.getTimeInMillis();
		cal.setTime(sdf.parse(endTime));
		long time2 = cal.getTimeInMillis();
		long between_days = (time2 - time1) / (1000 * 3600 * 24);
		return Integer.parseInt(String.valueOf(between_days));
	}

	/**
	 * 获取日志表后缀日期
	 * 
	 * @return
	 */
	public static String getTimeSixAndToString() {
		Date dt = new Date();
		DateFormat df = new SimpleDateFormat("yyyyMM");
		String nowTime = df.format(dt);
		return nowTime;
	}

	/**
	 * 获取下个月日志表后缀日期
	 * 
	 * @return
	 */
	public static String getNextTime() {
		Date dt = new Date();
		DateFormat df = new SimpleDateFormat("yyyyMM");
		String nowTime = df.format(getLastDate3(dt));
		return nowTime;
	}

	private static Date getLastDate3(Date date) {
		Calendar cal = Calendar.getInstance();
		cal.setTime(date);
		cal.add(Calendar.MONTH, +1);
		return cal.getTime();
	}

	/**
	 * 获取上个月日志表后缀日期
	 * 
	 * @return
	 */
	public static String getTimePrevMonthAndToString() {
		Date dt = new Date();
		DateFormat df = new SimpleDateFormat("yyyyMM");
		String nowTime = df.format(getLastDate(dt));
		return nowTime;
	}

	private static Date getLastDate(Date date) {
		Calendar cal = Calendar.getInstance();
		cal.setTime(date);
		cal.add(Calendar.MONTH, -1);
		return cal.getTime();
	}

	/**
	 * 获取上上个月的日志表中的日期后缀表达式
	 * 
	 * @return
	 */
	public static String getTimeVorMonthAndToString() {
		Date dt = new Date();
		DateFormat df = new SimpleDateFormat("yyyyMM");
		String nowTime = df.format(getLastDate2(dt));
		return nowTime;
	};

	private static Date getLastDate2(Date date) {
		Calendar cal = Calendar.getInstance();
		cal.setTime(date);
		cal.add(Calendar.MONTH, -2);
		return cal.getTime();
	}

	/**
	 * 获取当前日期(2016-12-29 11:23:09)
	 * 
	 * @return
	 */
	public static String getTimeAndToString() {
		Date dt = new Date();
		DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		String nowTime = df.format(dt);
		return nowTime;
	}

	/**
	 * 获取当前日期(2016-12-29)
	 * 
	 * @return
	 */
	public static String getTime() {
		Date dt = new Date();
		DateFormat df = new SimpleDateFormat("yyyy-MM-dd");
		String nowTime = df.format(dt);
		return nowTime;
	}

	/**
	 * 获取当前日期字符串(20161229112321)
	 * 
	 * @return
	 */
	public static String getToString() {
		Date dt = new Date();
		DateFormat df = new SimpleDateFormat("yyyyMMddHHmmss");
		String nowTime = df.format(dt);
		return nowTime;
	}

	/**
	 * 获取当前日期字符串(20161229112321)
	 * 
	 * @return
	 */
	public static String getTimeToString() {
		Date dt = new Date();
		DateFormat df = new SimpleDateFormat("yyyyMMdd");
		String nowTime = df.format(dt);
		return nowTime;
	}

	/**
	 * 获取一周前的时间
	 * 
	 * @return
	 */
	public static String getTimePreWeekToString() {
		Date dt = new Date();
		DateFormat df = new SimpleDateFormat("yyyyMMdd");
		Calendar nowTime = Calendar.getInstance();
		nowTime.setTime(dt);
		nowTime.add(Calendar.DATE, -7);
		String preWeek = df.format(nowTime.getTime());
		return preWeek;
	}

	public static String getUUID() {
		UUID uuid = UUID.randomUUID();
		String str = uuid.toString();
		System.out.println(str);
		// 获取前5位
		return str.substring(0, 4);
	}
	
	/**
	 * 判断是否为空
	 * @param str
	 * @return
	 */
	public static boolean isNull(String str){
		if(str==null||str.equals("")||str.equals("null")){
			return true;
		}else{
			return false;
		}
	}
	
	/**
	* 检测网络资源是否存在　
	* 
	* @param strUrl
	* @return
	*/
	public static boolean isNetFileAvailable(String strUrl) {
		InputStream netFileInputStream = null;
		try {
			URL url = new URL(strUrl);
			URLConnection urlConn = url.openConnection();
			netFileInputStream = urlConn.getInputStream();
			if (null != netFileInputStream) {
				return true;
			} else {
				return false;
			}
		} catch (IOException e) {
			return false;
		} finally {
			try {
				if (netFileInputStream != null)
					netFileInputStream.close();
			} catch (IOException e) {
			}
		}
	}

	/**
	 * 判断是不是数字
	 * @param str
	 * @return
	 */
	public static boolean isNumeric(String str) {
		Pattern pattern = Pattern.compile("[0-9]*");
		Matcher isNum = pattern.matcher(str);
		if (!isNum.matches()) {
			return false;
		}
		return true;
	}
	
	/**
	 * 检测手机号是否合格
	 * @param mobiles
	 * @return
	 */
	public static boolean isPhoneNO(String mobiles) {
		Pattern p = Pattern.compile("^((13[0-9])|(15[^4])|(18[0,2,3,5-9])|(17[0-8])|(147))\\d{8}$");
		Matcher m = p.matcher(mobiles);
		return m.matches();
	}
	
	/**
	 * 检测400/800开头的电话号码是否合格
	 * @param mobiles
	 * @return
	 */
	public static boolean isNumber(String mobiles) {
		Pattern p = Pattern.compile("/^(4|8)00-[0-9]{3}-[0-9]{4}$/");
		Matcher m = p.matcher(mobiles);
		return m.matches();
	}
	
	/**
	 * 检测电话号码是否合格
	 * @param mobiles
	 * @return
	 */
	 public static boolean isPhone(final String str) {  
	     Pattern p1 = null, p2 = null;  
	     Matcher m = null;  
	     boolean b = false;  
	     p1 = Pattern.compile("^[0][1-9]{2,3}-[0-9]{5,10}$");  // 验证带区号的  
	     p2 = Pattern.compile("^[1-9]{1}[0-9]{5,8}$");         // 验证没有区号的  
	     if (str.length() > 9) {  
	        m = p1.matcher(str);  
	        b = m.matches();  
	     } else {  
	         m = p2.matcher(str);  
	        b = m.matches();  
	     }  
	     return b;  
	 }
	
	
	/**
	* 验证邮箱
	* @param 待验证的字符串
	* @return 如果是符合的字符串,返回 <b>true </b>,否则为 <b>false </b>
	*/
	public static boolean isEmail(String str) {
		String regex = "^([\\w-\\.]+)@((\\[[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.)|(([\\w-]+\\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\\]?)$";
		return match(regex, str);
	}

	/**
	* 验证IP地址
	* @param 待验证的字符串
	* @return 如果是符合格式的字符串,返回 <b>true </b>,否则为 <b>false </b>
	*/
	public static boolean isIP(String str) {
		String num = "(25[0-5]|2[0-4]\\d|[0-1]\\d{2}|[1-9]?\\d)";
		String regex = "^" + num + "\\." + num + "\\." + num + "\\." + num + "$";
		return match(regex, str);
	}

	/**
	* 验证网址Url
	* @param 待验证的字符串
	* @return 如果是符合格式的字符串,返回 <b>true </b>,否则为 <b>false </b>
	*/
	public static boolean IsUrl(String str) {
		String regex = "http(s)?://([\\w-]+\\.)+[\\w-]+(/[\\w- ./?%&=]*)?";
		return match(regex, str);
	}
	
	/**
	* 验证输入密码条件(字符与数据同时出现)
	* @param 待验证的字符串
	* @return 如果是符合格式的字符串,返回 <b>true </b>,否则为 <b>false </b>
	*/
	public static boolean IsPassword(String str) {
		String regex = "[A-Za-z]+[0-9]";
		return match(regex, str);
	}

	/**
	* 验证输入密码长度 (6-18位)
	* @param 待验证的字符串
	* @return 如果是符合格式的字符串,返回 <b>true </b>,否则为 <b>false </b>
	*/
	public static boolean IsPasswLength(String str) {
		String regex = "^\\d{6,18}$";
		return match(regex, str);
	}

	/**
	* 验证输入邮政编号
	* @param 待验证的字符串
	* @return 如果是符合格式的字符串,返回 <b>true </b>,否则为 <b>false </b>
	*/
	public static boolean IsPostalcode(String str) {
		String regex = "^\\d{6}$";
		return match(regex, str);
	}
	
	/**
	* 验证输入身份证号
	* @param 待验证的字符串
	* @return 如果是符合格式的字符串,返回 <b>true </b>,否则为 <b>false </b>
	*/
	public static boolean IsIDcard(String str) {
		String regex = "(^\\d{18}$)|(^\\d{15}$)";
		return match(regex, str);
	}

	/**
	* 验证输入两位小数
	* @param 待验证的字符串
	* @return 如果是符合格式的字符串,返回 <b>true </b>,否则为 <b>false </b>
	*/
	public static boolean IsDecimal(String str) {
		String regex = "^[0-9]+(.[0-9]{2})?$";
		return match(regex, str);
	}

	/**
	* 验证输入一年的12个月
	* @param 待验证的字符串
	* @return 如果是符合格式的字符串,返回 <b>true </b>,否则为 <b>false </b>
	*/
	public static boolean IsMonth(String str) {
		String regex = "^(0?[[1-9]|1[0-2])$";
		return match(regex, str);
	}

	/**
	* 验证输入一个月的31天
	* @param 待验证的字符串
	* @return 如果是符合格式的字符串,返回 <b>true </b>,否则为 <b>false </b>
	*/
	public static boolean IsDay(String str) {
		String regex = "^((0?[1-9])|((1|2)[0-9])|30|31)$";
		return match(regex, str);
	}

	/**
	* 验证日期时间
	* @param 待验证的字符串
	* @return 如果是符合网址格式的字符串,返回 <b>true </b>,否则为 <b>false </b>
	*/
	public static boolean isDate(String str) {
		// 严格验证时间格式的(匹配[2002-01-31], [1997-04-30],
		// [2004-01-01])不匹配([2002-01-32], [2003-02-29], [04-01-01])
		// String regex =
		// "^((((19|20)(([02468][048])|([13579][26]))-02-29))|((20[0-9][0-9])|(19[0-9][0-9]))-((((0[1-9])|(1[0-2]))-((0[1-9])|(1\\d)|(2[0-8])))|((((0[13578])|(1[02]))-31)|(((01,3-9])|(1[0-2]))-(29|30)))))$";
		// 没加时间验证的YYYY-MM-DD
		// String regex =
		// "^((((1[6-9]|[2-9]\\d)\\d{2})-(0?[13578]|1[02])-(0?[1-9]|[12]\\d|3[01]))|(((1[6-9]|[2-9]\\d)\\d{2})-(0?[13456789]|1[012])-(0?[1-9]|[12]\\d|30))|(((1[6-9]|[2-9]\\d)\\d{2})-0?2-(0?[1-9]|1\\d|2[0-8]))|(((1[6-9]|[2-9]\\d)(0[48]|[2468][048]|[13579][26])|((16|[2468][048]|[3579][26])00))-0?2-29-))$";
		// 加了时间验证的YYYY-MM-DD 00:00:00
		String regex = "^((((1[6-9]|[2-9]\\d)\\d{2})-(0?[13578]|1[02])-(0?[1-9]|[12]\\d|3[01]))|(((1[6-9]|[2-9]\\d)\\d{2})-(0?[13456789]|1[012])-(0?[1-9]|[12]\\d|30))|(((1[6-9]|[2-9]\\d)\\d{2})-0?2-(0?[1-9]|1\\d|2[0-8]))|(((1[6-9]|[2-9]\\d)(0[48]|[2468][048]|[13579][26])|((16|[2468][048]|[3579][26])00))-0?2-29-)) (20|21|22|23|[0-1]?\\d):[0-5]?\\d:[0-5]?\\d$";
		return match(regex, str);
	}

	/**
	* 验证数字输入
	* @param 待验证的字符串
	* @return 如果是符合格式的字符串,返回 <b>true </b>,否则为 <b>false </b>
	*/
	public static boolean IsNumber(String str) {
		String regex = "^[0-9]*$";
		return match(regex, str);
	}

	/**
	* 验证非零的正整数
	* @param 待验证的字符串
	* @return 如果是符合格式的字符串,返回 <b>true </b>,否则为 <b>false </b>
	*/
	public static boolean IsIntNumber(String str) {
		String regex = "^\\+?[1-9][0-9]*$";
		return match(regex, str);
	}

	/**
	* 验证大写字母
	* @param 待验证的字符串
	* @return 如果是符合格式的字符串,返回 <b>true </b>,否则为 <b>false </b>
	*/
	public static boolean IsUpChar(String str) {
		String regex = "^[A-Z]+$";
		return match(regex, str);
	}

	/**
	* 验证小写字母
	* @param 待验证的字符串
	* @return 如果是符合格式的字符串,返回 <b>true </b>,否则为 <b>false </b>
	*/
	public static boolean IsLowChar(String str) {
		String regex = "^[a-z]+$";
		return match(regex, str);
	}

	/**
	* 验证验证输入字母
	* @param 待验证的字符串
	* @return 如果是符合格式的字符串,返回 <b>true </b>,否则为 <b>false </b>
	*/
	public static boolean IsLetter(String str) {
		String regex = "^[A-Za-z]+$";
		return match(regex, str);
	}

	/**
	* 验证验证输入汉字
	* @param 待验证的字符串
	* @return 如果是符合格式的字符串,返回 <b>true </b>,否则为 <b>false </b>
	*/
	public static boolean IsChinese(String str) {
		String regex = "^[\u4e00-\u9fa5],{0,}$";
		return match(regex, str);
	}

	/**
	* 验证验证输入字符串
	* @param 待验证的字符串
	* @return 如果是符合格式的字符串,返回 <b>true </b>,否则为 <b>false </b>
	*/
	public static boolean IsLength(String str) {
		String regex = "^.{8,}$";
		return match(regex, str);
	}
	
	/**
	* @param regex
	* 正则表达式字符串
	* @param str
	* 要匹配的字符串
	* @return 如果str 符合 regex的正则表达式格式,返回true, 否则返回 false;
	*/
	private static boolean match(String regex, String str) {
		Pattern pattern = Pattern.compile(regex);
		Matcher matcher = pattern.matcher(str);
		return matcher.matches();
	}
	
	/**
	 * 获取当前日期(2016-12-29)
	 * @return
	 */
	public static String getDaytoString() {
		Date dt = new Date();
		DateFormat df = new SimpleDateFormat("yyyy-MM-dd");
		return df.format(dt);
	}
	
	/**
	 * 获取当前日期(2016-12)
	 * @return
	 */
	public static String getMonthtoString() {
		Date dt = new Date();
		DateFormat df = new SimpleDateFormat("yyyy-MM");
		return df.format(dt);
	}
	
	/**
	 * 获取当前日期(08:45)
	 * @return
	 */
	public static String getHourAndMinitoString() {
		Date dt = new Date();
		DateFormat df = new SimpleDateFormat("HH:mm");
		return df.format(dt);
	}
	
	/**
	 * 在当前时间上加上几分钟
	 * @return
	 */
	public static String getDelayByNowTimetoString(String limitTime) {
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		Calendar nowTime = Calendar.getInstance();
		nowTime.add(Calendar.MINUTE, Integer.parseInt(limitTime));
		return sdf.format(nowTime.getTime());
	}
	
	/** 
	 * 判断某一时间是否在一个区间内 
	 *  
	 * @param sourceTime 
	 *            时间区间,半闭合,如[10:00-20:00) 
	 * @param curTime 
	 *            需要判断的时间 如10:00 
	 * @return  
	 * @throws IllegalArgumentException 
	 */  
	public static boolean isInTime(String sourceTime, String curTime) {  
	    if (sourceTime == null || !sourceTime.contains("-") || !sourceTime.contains(":")) {  
	        throw new IllegalArgumentException("时间段不能为空");  
	    }  
	    if (curTime == null || !curTime.contains(":")) {  
	        throw new IllegalArgumentException("当前时间不能为空");  
	    }  
	    String[] args = sourceTime.split("-");  
	    SimpleDateFormat sdf = new SimpleDateFormat("HH:mm");  
	    try {  
	        long now = sdf.parse(curTime).getTime();  
	        long start = sdf.parse(args[0]).getTime();  
	        long end = sdf.parse(args[1]).getTime();  
	        if (args[1].equals("00:00")) {  
	            args[1] = "24:00";  
	        }  
	        if (end < start) {  
	            if (now >= end && now < start) {  
	                return false;  
	            } else {  
	                return true;  
	            }  
	        }   
	        else {  
	            if (now >= start && now < end) {  
	                return true;  
	            } else {  
	                return false;  
	            }  
	        }  
	    } catch (ParseException e) {  
	        throw new IllegalArgumentException("非法参数");  
	    }  
	  
	}  
	
	/**
	 * 字节码转换  11.98M
	 * @param fileS
	 * @return
	 */
	public static String FormetFileSize(long fileS) {//转换文件大小
        DecimalFormat df = new DecimalFormat("#.00");
        String fileSizeString = "";
        if (fileS < 1024) {
            fileSizeString = df.format((double) fileS) + "B";
        } else if (fileS < 1048576) {
            fileSizeString = df.format((double) fileS / 1024) + "K";
        } else if (fileS < 1073741824) {
            fileSizeString = df.format((double) fileS / 1048576) + "M";
        } else {
            fileSizeString = df.format((double) fileS / 1073741824) + "G";
        }
        return fileSizeString;
    }
	
	/**
	 * 字节码单位转换  M
	 * @param fileS
	 * @return
	 */
	public static Object FormetFileUnit(long fileS) {
        String fileSizeString = "";
        if (fileS < 1024) {
            fileSizeString = "B";
        } else if (fileS < 1048576) {
            fileSizeString = "K";
        } else if (fileS < 1073741824) {
            fileSizeString = "M";
        } else {
            fileSizeString = "G";
        }
        return fileSizeString;
	}
	
	/**
	 * 将数据转换为树
	 * @param beans
	 * @return
	 */
	public static List<Map<String, Object>> createDataToTree(List<Map<String, Object>> beans){
		List<Map<String, Object>> treeAncestors = new ArrayList<>();
		List<Map<String, Object>> treeParent = new ArrayList<>();
		List<Map<String, Object>> treeChild = new ArrayList<>();
		
		for(Map<String, Object> bean : beans){//遍历beans获取一级菜单
			if(bean.get("type").toString().equals(Constants.PERMISSION_MENU_FIRST)){//一级菜单
				bean.put("isParent", true);
				treeAncestors.add(bean);
			}
		}
		
		for(Map<String, Object> bean : beans){//遍历beans获取二级菜单
			if(bean.get("type").toString().equals(Constants.PERMISSION_MENU_SECOND)){//二级菜单
				bean.put("isParent", true);
				treeParent.add(bean);
			}
		}
		
		for(Map<String, Object> item : treeParent){//遍历beans获取三级权限，将三级权限的属性存放到treeParent中
			treeChild.clear();
			for(Map<String, Object> bean : beans){
				if(bean.get("type").toString().equals(Constants.PERMISSION_MENU_THREE)){//三级权限
					if(bean.get("parentId").toString().equals(item.get("id").toString())){
						treeChild.add(bean);
						bean.put("isParent", false);
					}
				}
			}
			item.put("child", treeChild);
		}
		
		for(Map<String, Object> item : treeAncestors){//遍历treeParent获取id,并存放到treeAncestors中
			treeChild.clear();
			for(Map<String, Object> bean : treeParent){
				if(bean.get("parentId").toString().equals(item.get("id").toString())){
					treeChild.add(bean);
				}
			}
			item.put("child", treeChild);
		}
		
		return treeAncestors;
	}
	
	/**
	 * 将数据转换成菜单
	 * @param beans
	 * @return
	 */
	public static List<Map<String, Object>> createDataToMenu(List<Map<String, Object>> beans){
		List<Map<String, Object>> treeAncestors = new ArrayList<>();
		for(Map<String, Object> bean : beans){
			if(bean.get("type").toString().equals(Constants.PERMISSION_MENU_FIRST)){//一级菜单
				treeAncestors.add(bean);
			}
		}
		
		for(Map<String, Object> bean : treeAncestors){
			List<Map<String, Object>> treeParent = new ArrayList<>();
			for(Map<String, Object> item : beans){
				if(item.get("pId").toString().equals(bean.get("id").toString())){
					treeParent.add(item);
				}
			}
			bean.put("menuList", treeParent);
			bean.put("size", treeParent.size());
		}
		return treeAncestors;
				
	}

}
